
package com.zsrt.day0523.jdbc.ch01.impl;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import com.zsrt.day0523.jdbc.ch01.dao.EmployeeDao;

public class EmployeeSqlImpl implements EmployeeDao{

	@Override
	public int add(String str) throws Exception {
		
		Connection connection = getMYSQL();
		Statement statement = connection.createStatement();
		int i = statement.executeUpdate(str);
		return i;
	}

	private Connection getMYSQL() throws FileNotFoundException, IOException, ClassNotFoundException, SQLException {
		Properties prop = new Properties();
		FileInputStream in = new FileInputStream("resources/jdbc.sql.properties");
		prop.load(in);
		
		
		String className=prop.getProperty("jdbc.driver");
		Class.forName(className);
	
		String url=prop.getProperty("jdbc.url");
		String user = prop.getProperty("jdbc.user");
		String password = prop.getProperty("jdbc.password");
		Connection connection = DriverManager.getConnection(url, user, password);
		return connection;
	}

	@Override
	public int delete(String str) throws Exception {
		Connection connection = getMYSQL();
		Statement statement = connection.createStatement();
		int i = statement.executeUpdate(str);
		return i;
	}

}
